package sad.controle;

import sad.util.Constantes;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import sad.dao.DAO;
import sad.dao.QuestaoTableDAO;
import sad.util.DAOEvent;
import sad.visao.DialogAbstrato;
import sad.visao.FabricaDeDialog;
import sad.visao.ListQuestaoDialog;

public class RelatorioQuestaoControle extends AbstractControl{

  private ListQuestaoDialog v_rel_questao;

  public RelatorioQuestaoControle(DialogAbstrato v) {
    this.v_rel_questao = (ListQuestaoDialog) v;
    addOuvinte();
    refreshRelatorio();
    v_rel_questao.setModal(true);
    v_rel_questao.setVisible(true);
  }
  
// <editor-fold defaultstate="collapsed" desc="Responde a eventos com origem nas visões">
    @Override
    public void actionPerformed(ActionEvent e) {
        /*
        if(e.getActionCommand().equals(Constantes.NOVO_RELATORIO)){
            v_rel_questao.resetMessage();
            FabricaDeDialog.criarDialog(null, "Questao",null);
        }
        if(e.getActionCommand().equals(Constantes.EDITAR_PROFESSOR)){
            v_rel_questao.resetMessage();
            if(v_rel_questao.getSelectedQuestao()==-1){
                QuestaoTableDAO.getInstance().erroField("vazio", "Questao");
            }else{
                Object[] editable = QuestaoTableDAO.getInstance().isEditable(
                                        v_rel_questao.getSelectedQuestao());
                FabricaDeDialog.criarDialog(null, "Questao", editable);
            }
        }
        if(e.getActionCommand().equals(Constantes.CANCELAR_RELATORIO)){

            QuestaoTableDAO.getInstance().removeDAOOuvinte(this);
                        DAO.closeObjectContainer();
            v_rel_questao.close();
        }
        if(e.getActionCommand().equals(Constantes.EXCLUIR)){
            if(v_rel_questao.getSelectedQuestao()==-1){
                QuestaoTableDAO.getInstance().erroField("vazio", "Questao");
            }else{
                QuestaoTableDAO.getInstance().removeQuestao(
                    v_rel_questao.getSelectedQuestao());
            }        
        }*/
    }

    @Override
    public void windowClosed(WindowEvent e){
        switch(e.getID()){
           case WindowEvent.WINDOW_CLOSING:
                QuestaoTableDAO.getInstance().removeDAOOuvinte(this);
                DAO.closeObjectContainer();
                v_rel_questao.close();
                break;
        }
    }// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Enchaminha eventos com origem no DAO">
    @Override
    public void daoChange(DAOEvent e) {
        v_rel_questao.modelDAOChange(e);
    }// </editor-fold>
    
    private void addOuvinte() {
        v_rel_questao.addActionListener(this);
        QuestaoTableDAO.getInstance().addDAOOuvinte(this);
    }

    private void refreshRelatorio() {
        QuestaoTableDAO.createTableQuestao();
    //    v_rel_questao.setTblProdutos(
      //          QuestaoTableDAO.getInstance().getTableQuestao());
    }
}
